{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "fb9ebfb0",
   "metadata": {},
   "source": [
    "# 线性卷积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed9ceff7",
   "metadata": {},
   "source": [
    "求序列x=\\[3,11,7,0,-11,4,2\\]和h=\\[2,3,0,-5,2,1\\]的线性卷积。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "68e7198b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX8AAAESCAYAAAAVLtXjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAWBUlEQVR4nO3df5BV533f8fc368XdCstI1hZraQghISRqVBll60AkOUiVjKjjilJbVsc/EkkelFRNf6TBFmPZiTNxpQhHk1YOipDxNIkTxdiDiNXEAdsyFU7A7tK1RSOX2mMjqUtIcGCRpdkIunz7xz0LC17Mr3vP2XvO+zWzw73Pueee77nsfu65z3mecyMzkSQ1y/dVXYAkqXyGvyQ1kOEvSQ1k+EtSAxn+ktRAhr80hYh4TUS8ouo6pE4x/NUYEXFzRFwx6f5bIuKnI2Kqv4OtwA+dsv77I+Kes9jOdRExeBaP+4cRcXtExNnUL7WT4a9GKAL+N4G/N6n5GuB1wAcjYvUpq7wMHCnW/VBE/Mzktime/yMR8bPF3XcDP1y0/7uI+PVJj/uxiPh8RHwD2Ab8IPDGiNgdEUPFz3BE/OaF7bH0vRn+aop3AJuAv4uIf1q0vQT8HXA/8NcR8fpoeSVwDHhTRMwCfgL466Lt2KTHAFB0D/0GMKdougLYXTzmGuC3I2JGsez/ALfTeoP4XGZ+ADgEfDUzBzNzEFgNXNaRV0Eq2Kep2ouIBcAvAP8M+CjwdES8BvgpWoF9K3AQ+Pu0Qv6jxao/DvwcsAh4GJgNJPBO4HlgRfG4twJr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ey84XMPDypqRbZUufwf5ET/cUzqdm+FkfHnwTWZOb5XvdouroRuDsitgGvi4iPVlxPO30DmF/cHuT8r1k1XV0CXBkRPcBPAnUcS16LbOnKos/SLk58HLsK2FtdKR1xJ3A18L6I2BYRb6u6oHbJzDdk5tLMXAp8JTPfXXVNbbQBuD4ingL+Na2T2nVyH61JUIeBS4HHqi2nI2qRLbWd5BURFwPbgc8Dy4HFp3x0k6SzFhHbMnNpXbKltuEPx8/S3wQ8VfSxStIFq0O21Dr8JUlTq3OfvyTpNAx/SWogw1+SGsjwl6QGekXVBUjdKiJ+FegFrgMuBm7u1pEfah6P/KUL88OZ+QZgE3BD1cVIZ8vwly7M7xX/PgfU7jsVVF+Gv3RhXqq6AOl8GP6S1EDO8JWkBvLIX5IayPCXpAYy/CWpgQx/SWogw1+SGsjwl6QGMvwlqYH+P42Zv/uXCiGJAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from math import *\n",
    "def conv_m(x,h):\n",
    " nx=len(x)\n",
    " nh=len(h)\n",
    " ny=nx+nh-1\n",
    " y=np.zeros(ny)#初始化\n",
    " for n in np.arange(ny):\n",
    "     y[n]=0\n",
    "     for m in np.arange(nh):\n",
    "         k=n-m+1\n",
    "         if k>=1 and k<=nx:\n",
    "             y[n]=y[n]+h[m]*x[k-1]#卷积\n",
    " plt.rcParams['font.sans-serif'] = ['SimHei']\n",
    " plt.rcParams['axes.unicode_minus'] = False\n",
    " plt.stem(y)\n",
    " plt.title('线性卷积')\n",
    " plt.xlabel('n')\n",
    " plt.ylabel('y')\n",
    " plt.show()\n",
    "conv_m(np.array([3,11,7,0,-11,4,2]),np.array([2,3,0,-5,2,1]))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cc27dee9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
